/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.colswe.solestac.dao;

import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.Query;
import org.colswe.solestac.entity.Program;

/**
 *
 * @author David Cendales
 */
public class ProgramDao {
    
    /**Search all programs in the system.
     * @param em EntityManager object to make the operation
     * @return All registered programs
     */
    public List<Program> searchAll(final EntityManager em) {
        Query q = em.createNamedQuery("Program.findAll");
        return (List<Program>) q.getResultList();
    }
    
    /**Search a program by name.
     * @param em EntityManager object to make the operation
     * @param name Program name given by the user
     * @return program by name
     */
    public List<Program> searchByName(final String name, final EntityManager em) {
        Query q = em.createNamedQuery("Program.findByName").setParameter("name", name);
        return (List<Program>) q.getResultList();
    }
    
     /**Update a program.
     * @param p The program object that will be updated
     * @param em EntityManager object to make the operation
     */
    public void update(final Program p, final EntityManager em) {
        em.merge(p);
    }
}
